package com.ylbh.modules.coupon.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.coupon.dto.*;
import com.ylbh.common.pojo.coupon.vo.CouponDetailsVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.coupon.service.CouponService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 优惠券
 * @author czx
 * @date 2019-05-10
 */
@RestController
@RequestMapping("coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    @ApiOperation("优惠券使用记录")
    @RequestMapping("queryUsageRecordList")
    @RequiresPermissions("coupon:queryUsageRecordList")
    public CommonResult<PageUtils> queryUsageRecordList(UsageRecordDTO usageRecordDTO) {
        PageUtils pageUtils = couponService.queryUsageRecordList(usageRecordDTO);
        return Ref.ok(pageUtils);
    }

    @ApiOperation("超级大玩家开通记录")
    @RequestMapping("queryOpeningRecordList")
    @RequiresPermissions("coupon:queryOpeningRecordList")
    public CommonResult<PageUtils> queryOpeningRecordList(OpeningRecordDTO openingRecordDTO) {
        PageUtils pageUtils = couponService.queryOpeningRecordList(openingRecordDTO);
        return Ref.ok(pageUtils);
    }

    @ApiOperation("优惠券领取记录")
    @RequestMapping("queryCollectionRecordsList")
    @RequiresPermissions("coupon:queryCollectionRecordsList")
    public CommonResult<PageUtils> queryCollectionRecordsList(CollectionRecordsDTO collectionRecordsDTO) {
        PageUtils pageUtils = couponService.queryCollectionRecordsList(collectionRecordsDTO);
        return Ref.ok(pageUtils);
    }

    @ApiOperation("优惠券信息列表")
    @RequestMapping("queryCouponList")
    @RequiresPermissions("coupon:queryCouponList")
    public CommonResult<PageUtils> queryCouponList(CouponListDTO couponListDTO) {
        PageUtils pageUtils = couponService.queryCouponList(couponListDTO);
        return Ref.ok(pageUtils);
    }

    @ApiOperation("优惠券信息详情")
    @RequestMapping("queryCouponDetailsById/{goodsId}")
    @RequiresPermissions("coupon:queryCouponDetailsById")
    public CommonResult<CouponDetailsVO> queryCouponDetailsById(@PathVariable(value = "goodsId")Long goodsId) {
        CouponDetailsVO details = couponService.queryCouponDetailsById(goodsId);
        return Ref.ok(details);
    }

    @SysLog("优惠券上下架")
    @ApiOperation("优惠券上下架")
    @RequestMapping("modifyUpperAndLowerFrames")
    @RequiresPermissions("coupon:modifyUpperAndLowerFrames")
    public CommonResult<Void> modifyUpperAndLowerFrames(@RequestBody CouponPassDTO couponPassDTO) {
        couponService.modifyUpperAndLowerFrames(couponPassDTO.getGoodsId(), couponPassDTO.getIsSale());
        return Ref.ok();
    }

    @SysLog("优惠券审核操作")
    @ApiOperation("优惠券审核操作")
    @RequestMapping("modifyAdoptById")
    @RequiresPermissions("coupon:modifyAdoptById")
    public CommonResult<Void> modifyAdoptById(@RequestBody CouponPassDTO couponPassDTO) {
        couponService.modifyAdoptById(couponPassDTO);
        return Ref.ok();
    }
}
